package problem80;

//80.删除有序数组中的重复项2
//https://leetcode.cn/problems/remove-duplicates-from-sorted-array-ii/description/?envType=study-plan-v2&envId=top-interview-150

class Solution {
    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        int count = 1;
        int i = 0, j = 0;
        for(i = 1, j = 1; j<n; j++) {
            if(nums[j] == nums[j-1]) count++;
            else count = 1;
            if(count <= 2) nums[i++] = nums[j];
        }
        return i;
    }
}